/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __A_SYNC_H__
#define __A_SYNC_H__

/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <x_compiler.h>
/* includes (local) ----------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/

/**
 * mb - read write memory barrier
 *
 * return: NA
 */
static __always_inline void mb(void)
{
    __asm__ __volatile__("dmb #0xf" : : : "memory");
}

/**
 * rmb - read memory barrier
 *
 * return: NA
 */
static __always_inline void rmb(void)
{
    __asm__ __volatile__("dmb #0xf" : : : "memory");
}

/**
 * wmb - write memory barrier
 *
 * return: NA
 */
static __always_inline void wmb(void)
{
    __asm__ __volatile__("dmb #0xf" : : : "memory");
}

/**
 * dsb - data synchronization barrier
 *
 * return: NA
 */
static __always_inline void dsb(void)
{
    __asm__ __volatile__("dsb #0xf" : : : "memory");
}

/**
 * isb - instruction synchronization barrier
 *
 * return: NA
 */
static __always_inline void isb(void)
{
    __asm__ __volatile__("isb #0xf" : : : "memory");
}

/* externs -------------------------------------------------------------------*/

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __A_SYNC_H__ */
